import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/public/views/public_appBar.dart';
import 'package:honeypotflutter/public/views/public_refresh.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import '../../api/cabinetFormApi.dart';
import '../../model/cabinet_form_earnings_info_model.dart';
import '../../views/cabinet_form_earnings_info_item.dart';
import 'logic.dart';

class CabinetFormEarningsInfoPage extends StatefulWidget {
  const CabinetFormEarningsInfoPage({Key? key}) : super(key: key);

  @override
  State<CabinetFormEarningsInfoPage> createState() => _CabinetFormEarningsInfoPageState();
}

class _CabinetFormEarningsInfoPageState extends State<CabinetFormEarningsInfoPage> {
  final CabinetFormEarningsInfoLogic logic = Get.put(CabinetFormEarningsInfoLogic());
  int page = 1;
  String date = "";

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    date = Get.arguments["date"];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: MGColors.whileColor,
      appBar: HLAppBar(navigationTitle: "柜机收益报表"),
      body: Container(
        margin: EdgeInsets.only(left: 16, right: 16),
        child: Column(
          children: [
            CabinetFormEarningsInfoItem(),
            Expanded(
                child: HLRefresh<CabinetFormEarningsInfoModel>(
              pageCount: 50,
              onLoading: () async {
                page += 1;
                return await CabinetFormApi.earningsInfo(page: page, date: date);
              },
              onRefresh: () async {
                page = 1;
                return await CabinetFormApi.earningsInfo(page: page, date: date);
              },
              snap: (date, int index) {
                return CabinetFormEarningsInfoItem(
                  itemModel: date,
                  color: MGColors.text1Color,
                  backColor: (index % 2 == 0) ? MGColors.whileColor : MGColors.backColor,
                );
              },
            ))
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<CabinetFormEarningsInfoLogic>();
    super.dispose();
  }
}
